package cn.doit.scala.day03

/**
 * @DATE 2021/12/27/11:42
 * @Author MDK
 * @Version 2021.2.2
 * */
object C04_Collect02 {
  def main(args: Array[String]): Unit = {
    val list: List[Any] = List[Any]("java", "scala", "sql", 12, 21, 23.22)

//    val pf =new PartialFunction[Any, String] {
//      override def isDefinedAt(x: Any): Boolean = {
//        x.isInstanceOf[String]
//      }
//
//      override def apply(v1: Any): String = {
//        v1.asInstanceOf[String].toUpperCase
//      }
//    }
//    val res =list.collect(pf)
//    res.foreach(println)
    list.collect(new PartialFunction[Any,String] {
      override def isDefinedAt(x: Any): Boolean = {
        x.isInstanceOf[String]
      }

      override def apply(v1: Any): String = {
        v1.asInstanceOf[String].toUpperCase
      }
    }).foreach(println)
  }
}
